<template>
    <input type="button" value="录入优惠券" @click="tiaoadddis">
    <input type="button" value="录入门店" @click="tiaomendian">
    <table>
        <tr>
            <td>会员名</td>
            <td>
                <input type="text" v-model="prist.name">
            </td>
        </tr>
        <tr>
            <td>会员密码</td>
            <td>
                <input type="password" v-model="prist.pwd">
            </td>
        </tr>
        <tr>
            <td>会员头像</td>
            <td>
                <input type="file" @change="upimages">
                <img :src="src" width="100" height="100" v-if="prist.picture">
            </td>
        </tr>
        <tr>
            <td>手机号</td>
            <td>
                <input type="text" v-model="prist.phone">
            </td>
        </tr>
        <tr>
            <td>身份证</td>
            <td>
                <input type="text" v-model="prist.idcard">
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="添加" @click="add">
            </td>
        </tr>
    </table>
  </template>
  
  <script setup lang="ts">
  import {reactive, toRefs} from 'vue'
  import axios from 'axios'
  import {useRouter,useRoute} from 'vue-router'

  const router=useRouter()
  const route=useRoute()

  let data:any=reactive({
    prist:{
        name:'',
        pwd:'',
        picture:'',
        phone:'',
        idcard:''
    },
    src:''
  })
  let {prist,src} =toRefs(data)

  const upimages=(e:any)=>{
    var form=new FormData()
    var obj=e.target.files[0]
    form.append('file',obj)
    axios({
        url:'/api/Upfile/Upload',
        method:'post',
        data:form
    })
    .then(res=>{
        src.value='https://localhost:7104'+res.data.filename;
        prist.value.picture=res.data.filename;
    })
  }

  const add=()=>{
    let obj={
        "mname": prist.value.name,
  "pwd": prist.value.pwd,
  "fileimages": prist.value.picture,
  "phone": prist.value.phone,
  "idcard": prist.value.idcard,
  "mstates": 1,
  "isdel": false
    }
    axios({
        url:'/api/Mem/Addmem',
        method:'post',
        data:obj
    })
    .then(res=>{
        if(res.data.data==1){
            alert("添加成功")
        }else{
            alert("添加失败")
        }
    })
  }

  const tiaoadddis=()=>{
    router.push('adddis')
  }

  const tiaomendian=()=>{
    router.push('addstore')
  }
  </script>
  
  <style scoped>
  
  </style>
  